package com.neusoft.elmboot.exception;

import com.neusoft.elmboot.common.Result;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

// 标记为全局异常处理器
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理上传文件过大的全局异常处理器。
     * @param ex
     * @return
     */
    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public Result<String> handleFileTooLargeException(MaxUploadSizeExceededException ex) {
        String errorMessage = "您上传的文件太大了！";
        return Result.fail(HttpStatus.BAD_REQUEST.value(),errorMessage);
    }

    @ExceptionHandler(UnLoginException.class)
    public Result<String> handleUnLoginException(UnLoginException ex){
        String errorMessage = "您尚未登录系统，请先登录，再进行其它操作！";
        return Result.fail(HttpStatus.BAD_REQUEST.value(),ex.getMessage());

    }
}